/*
 * @Author: liu wang wang
 * @Date: 2020-07-13 14:57:50
 * @LastEditTime: 2020-07-17 18:44:54
 * @LastEditors: liu wang wang
 * @Description: Alert弹框
 * @FilePath: \st-sdk-js\src\components\Alert.ts
 */
import Common from '../utils/Common';
import { alertInterface } from '../../types';
import store from '../utils/store';

class Alert extends Common {
    protected theme: string = '#fff';
    constructor() {
        super();
    }
    // 按钮区
    protected getBtns(btn:string,cb: Function): HTMLElement {
        const btnsBox = this.getDivofFlex();
        const sureBtn: HTMLElement = this.getButton({
            width: 80,
            height: 30,
            text: btn || '去创建版本',
            background: this.theme,
            color: '#fff',
            clickHandle: function () {
                cb && cb();
            }
        });
        const cancleBtn: HTMLElement = this.getButton({
            width: 80,
            height: 30,
            text: '取消',
            clickHandle: () => {
                this.close();
                store.getStore('close') && store.getStore('close')();
            }
        });
        this.setStyle(btnsBox, 'float:right;overflow:hidden;');
        this.setStyle(cancleBtn, 'border:1px solid rgba(203,203,203,1);margin-left:20px;');
        btnsBox.appendChild(sureBtn);
        btnsBox.appendChild(cancleBtn);
        return btnsBox;
    }
    public init({ theme, content, success, btn}: alertInterface): HTMLElement {
        this.theme = theme as string;
        const alertContent = this.createDiv();
        this.setStyle(alertContent, 'overflow:hidden;');
        const contentBox: HTMLElement = this.createDiv();
        contentBox.innerHTML = content;
        this.setStyle(contentBox, 'font-size:14px;color:#000;line-height:24px;margin-bottom:20px;');
        const btns = this.getBtns(btn,success);
        alertContent.appendChild(contentBox);
        alertContent.appendChild(btns);
        return alertContent;
    }
}

export default Alert;